<template>
  <div>
    <a-drawer :title="titleMap" :width="980" :visible.sync="visible"
      :body-style="{ 'padding-top': '0px', paddingBottom: '80px' }" @close="close">
      <!-- 进度条 -->
      <div class="drawerHeader">
        <a-steps :current="current" v-if="mode == 0 || mode == 1">
          <a-step :title="$t('user.verification-code.required111566149')" />
          <a-step :title="$t('user.verification-code.required111566150')" />
          <a-step :title="$t('user.verification-code.required111566151')" />
        </a-steps>
      </div>
      <a-form :form="form" layout="vertical">
        <div v-show="current == 0 || mode == 2">
          <!-- 注册识别风险 -->
          <a-form-item style="margin: 0" :label="$t('user.verification-code.required111566125')">
            <a-input v-decorator="[
      'RiskName',
      {
        rules: [
          {
            required: true,
            message: $t(
              'user.verification-code.required111566110577184'
            ),
          },
        ],
      },
    ]" :placeholder="$t('user.verification-code.required11156612511')" style="width: 900px"
              :disabled="disabled || mode == 2" />
          </a-form-item>
          <a-form-item style="margin: 0" :label="$t('user.verification-code.required111566153')">
            <a-textarea :auto-size="{ minRows: 3, maxRows: 10 }"
              :placeholder="$t('user.verification-code.required111566154')" :rows="3" v-decorator="[
      'RiskDetail',
      {
        rules: [
          {
            required: true,
            message: $t(
              'user.verification-code.required111566110577353'
            ),
          },
        ],
      },
    ]" style="width: 900px" :disabled="disabled || mode == 2" />
          </a-form-item>
          <a-row>
            <!-- 时间组合 -->
            <a-col :span="12">
              <a-form-item :label="$t('user.verification-code.required111566155')">
                <a-date-picker v-decorator="[
      'RiskStartTime',
      {
        rules: [
          {
            required: true,
            message: this.$t(
              'user.verification-code.required1115661105772855555'
            ),
          },
        ],
      },
    ]" format="YYYY-MM-DD" style="width: 440px" disabled @change="updateRiskDeadline" :placeholder="$t('user.verification-code.required1115661105772855555')
      " />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item :label="$t('user.verification-code.required111566156')">
                <a-date-picker v-decorator="[
      'RiskDeadline',
      {
        rules: [
          {
            required: true,
            message: this.$t(
              'user.verification-code.required11156611057728555555'
            ),
          },
        ],
      },
    ]" format="YYYY-MM-DD" style="width: 440px" :disabled="disabled || mode == 2" :disabled-date="disabledDateDeadline"
                  :placeholder="$t('user.verification-code.required11156611057728555555')
      " />
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <!-- 对象组合 -->
            <a-col :span="12">
              <!-- 风险负责人 -->
              <a-form-item :label="$t('user.verification-code.required111566128')" :colon="false" labelAlgin="left">
                <a-select v-decorator="[
      'RiskOwnerUserId',
      {
        rules: [
          {
            required: true,
            message: $t(
              'user.verification-code.required111566110577371442281431999'
            ),
          },
        ],
      },
    ]" :placeholder="$t('user.verification-code.required11156612811555')
      " show-search :default-active-first-option="false" @search="filte1rOption" :showArrow="false"
                  :filterOption="false" style="width: 440px" :disabled="disabled || mode == 2" :options="userList">
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item :label="$t('user.verification-code.required111566159')" :colon="false" labelAlgin="left">
                <a-select v-decorator="[
      'RiskDcoUserId',
      {
        rules: [
          {
            required: true,
            message: $t(
              'user.verification-code.required111566110577371442281431888'
            ),
          },
        ],
      },
    ]" :placeholder="$t('user.verification-code.required11156615911')
      " style="width: 440px" show-search option-filter-prop="children" :filter-option="filterOption"
                  :disabled="disabled || mode == 2">
                  <a-select-option v-for="item in userDCOList" :value="item.value" :key="item.value">
                    {{ item.label }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <!-- 风险组合 -->
            <a-col :span="12">
              <a-form-item :label="$t('user.verification-code.required111566160')" :colon="false">
                <a-select v-decorator="[
      'RiskLevel',
      {
        rules: [
          {
            required: true,
            message: $t(
              'user.verification-code.required111566110577356'
            ),
          },
        ],
      },
    ]" :placeholder="$t('user.verification-code.required11156616011')
      " style="width: 440px" :disabled="disabled || mode == 2" option-filter-prop="children"
                  :filter-option="filterOption" show-search>
                  <a-select-option v-for="item in riskLevel" :value="item.value" :key="item.value">
                    {{ item.label }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <!-- 风险类型 -->
              <a-form-item :label="$t('user.verification-code.required111566161')" :colon="false">
                <a-select v-decorator="[
      'RiskType',
      {
        rules: [
          {
            required: true,
            message: $t(
              'user.verification-code.required111566110577357'
            ),
          },
        ],
      },
    ]" option-filter-prop="children" :filter-option="filterOption" show-search :placeholder="$t('user.verification-code.required11156616111')
      " style="width: 440px" :disabled="disabled || mode == 2">
                  <a-select-option v-for="item in riskType" :value="item.value" :key="item.value">
                    {{ item.label }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>
          <!-- 风险备注 -->
          <a-form-item :label="$t('user.verification-code.required111566162')">
            <a-textarea v-decorator="[
      'RiskRemark',
      {
        rules: [
          {
            required: true,
            message: $t(
              'user.verification-code.required111566110577358'
            ),
          },
        ],
      },
    ]" :placeholder="$t('user.verification-code.required111566162')" :rows="4" style="width: 900px"
              :disabled="disabled || mode == 2" />
          </a-form-item>
          <!-- 风险处置计划描述 -->
          <a-form-item :label="$t('user.verification-code.required111566183')">
            <a-textarea v-decorator="['RiskDisposeDetail']"
              :placeholder="$t('user.verification-code.required11156618311')" style="width: 900px" :rows="4"
              :disabled="disabled || mode == 2" />
          </a-form-item>
          <a-form-item label="ID" v-if="mode == 1" class="hidden">
            <a-input v-decorator="['id']" :disabled="disabled || mode == 2" />
          </a-form-item>
          <!-- 上传提交 -->
          <a-button v-if="disabled || mode == 2" disabled icon="upload">
            {{ $t("user.verification-code.required111566163") }}
          </a-button>
          <a-upload name="file" :remove="delFile" :file-list="fileLists" :multiple="true" v-else
            :customRequest="handleChange">
            <a-button>
              <a-icon type="upload" />
              {{ $t("user.verification-code.required111566163") }}
            </a-button>
          </a-upload>
        </div>
        <div v-show="current == 1 || mode == 2">
          <!-- 风险缓解计划 -->
          <a-button v-if="mode != '2'" type="primary" icon="plus" @click="showModal('0')"
            :disabled="riskData.RiskState != 1">{{ $t("user.verification-code.required111566164") }}
          </a-button>
          <creatRiskAction :mode="mode" :riskId="riskId" :editId="editId" ref="creatRiskAction" @getList="getList"
            @finishList="checkActionListsFinish">
          </creatRiskAction>
          <a-table ref="table" :pagination="false" size="middle" style="margin-top: 20px" class="h-full overflow-x-auto"
            :dataSource="listData" :rowKey="(record) => record.Id">
            <a-table-column key="DpiaActionIdTag" data-index="DpiaActionIdTag" width="150">
              <span slot="title">{{
      $t("user.verification-code.required111566166")
    }}</span>
            </a-table-column>
            <a-table-column key="DpiaActionSource" data-index="DpiaActionSource" width="150">
              <span slot="title">{{
        $t("user.verification-code.required111566167")
      }}</span>
            </a-table-column>
            <a-table-column key="DpiaActionUserResponsible" data-index="DpiaActionUserResponsible" width="150">
              <span slot="title">{{
        $t("user.verification-code.required111566174")
      }}</span>
            </a-table-column>
            <a-table-column key="DpiaActionCreatetime" data-index="DpiaActionCreatetime" width="150">
              <span slot="title">{{
        $t("user.verification-code.required111566169")
      }}</span>
            </a-table-column>
            <a-table-column key="DpiaActionFinishTime" data-index="DpiaActionFinishTime" width="150">
              <span slot="title">{{
        $t("user.verification-code.required111566170")
      }}</span>
            </a-table-column>
            <a-table-column key="DpiaActionStatus" :title="$t('user.login.message-invalid-verification-code0011')">
              <template slot-scope="text, record">
                <span>
                  <div v-if="record.DpiaActionStatus === 1">
                    <a-badge color="blue" />
                    {{ $t("user.verification-code.required111566110577368") }}
                  </div>
                  <div v-else-if="record.DpiaActionStatus == 2">
                    <a-badge color="orange" />
                    {{ $t("user.verification-code.required1115661444444") }}
                  </div>
                  <div v-else-if="record.DpiaActionStatus === 3">
                    <a-badge color="purple" />
                    {{ $t("user.verification-code.required111566145") }}
                  </div>
                  <div v-else-if="record.DpiaActionStatus === 4">
                    <a-badge color="green" />
                    {{ $t("user.verification-code.required111566146") }}
                  </div>
                  <div v-else-if="record.DpiaActionStatus === 5">
                    <a-badge color="gray" />
                    {{ $t("user.verification-code.required11156612288889") }}
                  </div>
                </span>
              </template>
            </a-table-column>
            <a-table-column key="action" :title="$t('app.setting.othersettings')" style="margin-left: -15px">
              <template slot-scope="text, record">
                <span>
                  <a-space size="0">
                    <!-- 修改按钮 -->
                    <a-button type="link" :disabled="record.DpiaActionUserId ===
      $store.state.user.info.userid
      ? false
      : disabled || mode == 2
      " @click="showModal('1', record.Id)" block>{{
      $t("user.verification-code.required111566147")
    }}</a-button>
                    <!-- 删除按钮 -->
                    <a-popconfirm :title="$t('user.verification-code.required111566110577225')
      " :ok-text="$t('user.verification-code.required1166')" :cancel-text="$t('user.email.required11')"
                      :disabled="disabled || mode == 2" @confirm="() => del(record)">
                      <a-button type="link" size="small" block :disabled="disabled || mode == 2"
                        v-if="record.DpiaActionSource == '手动创建'">{{ $t("app.setting.copy") }}</a-button>
                    </a-popconfirm>
                  </a-space>
                </span>
              </template>
            </a-table-column>
          </a-table>
          <!-- 分页 -->
          <a-pagination class="mb-[130px]" size="small" v-model="pagination.page" :total="pagination.total"
            hideOnSinglePage :pageSize.sync="pagination.pageSize" @change="getList" />
        </div>
        <div v-if="current == 2">
          <!-- 完成 -->
          <success :type="StateType" @close="close"></success>
        </div>
        <div class="absolute right-0 bottom-0 w-full px-4 py-[10px] bg-white text-left z-1 flex justify-center">
          <!-- 上一步/下一步 -->
          <a-row class="w-full" :gutter="24">
            <a-col :span="12" v-if="current == 0 || mode == 0">
              <a-button class="w-full border-none hover:bg-[#3F8CFF] hover:bg-opacity-5 shadow" @click="close">{{
      $t("app.setting.themecolor.rr") }}
              </a-button>
            </a-col>
            <a-col :span="12" v-if="current == 0 && mode != 2">
              <a-button class="w-full border-none shadow" type="primary" @click.native.prevent="nextPage()">{{
      $t("user.verification-code.required11156622") }}
              </a-button>
              <!-- <a-button class="w-full border-none shadow" type="primary" @click.native.prevent="submit('add')">下一步</a-button> -->
            </a-col>
          </a-row>
          <!-- 提交时 -->
          <a-row class="w-full" :gutter="24" v-if="current == 1 || mode == 2">
            <a-col :span="8" v-show="mode != 2">
              <!-- 上一步 -->
              <a-button class="w-full border-none hover:bg-[#3F8CFF] hover:bg-opacity-5 shadow"
                @click="previousPage()">{{
      $t("user.verification-code.required11156611") }}
              </a-button>
            </a-col>
            <a-col :span="8" v-show="mode != 2">

              <!-- 保存草稿，状态1   Save as Draft   -->
              <a-button :loading="saveLoading" class="w-full border-none shadow" type="primary"
                @click.native.prevent="submit('edit')" v-if="riskData.RiskState == 1">
                <span v-if="!saveLoading">{{
      $t("user.register-result.view-mailbox")
    }}</span>
                <span v-else>{{ $t("app.setting.themecolor.tt") }}...</span>
              </a-button>
            </a-col>
            <a-col :span="8" v-show="mode != 2">
              <!-- 提交，状态3   submit！！！      -->
              <a-button :loading="subLoading1" class="w-full border-none shadow" type="primary"
                v-if="riskData.RiskState == 1" @click.native.prevent="submit('add')">
                <span v-if="!subLoading1">{{
      $t("user.verification-code.required111566165")
    }}</span>
                <span v-else>{{ $t("app.setting.themecolor.tt") }}...</span>
              </a-button>
            </a-col>
            <a-col :span="8" v-show="mode != 2">
              <!-- 提交审核，状态2   submit！！！    -->
              <a-button :loading="subLoading2" class="w-full border-none shadow" type="primary"
                v-if="riskData.RiskState == 3" @click.native.prevent="submit('review')"
                :disabled="!riskActionListsStatus">
                <span v-if="!subLoading2">{{ $t("risk.submit.review") }}</span>
                <span v-else>{{ $t("app.setting.themecolor.tt") }}...</span>
              </a-button>
            </a-col>
            <a-col :span="8" v-show="mode != 2">
              <!-- 保存，状态3     SAVE  -->
              <a-button :loading="subLoading1" class="w-full border-none shadow" type="primary"
                v-if="riskData.RiskState == 3" @click.native.prevent="submit('save')">
                <span v-if="!subLoading1">{{ $t("risk.save") }}</span>
                <span v-else>{{ $t("app.setting.themecolor.tt") }}...</span>
              </a-button>
            </a-col>
          </a-row>
        </div>
      </a-form>
    </a-drawer>
  </div>
</template>

<script>
import storage from "store";
import { riskCreate } from "@/api/risk/json";
import {
  delRiskFile,
  RISKActionList,
  RISKEditActionList,
  ristCreateAction,
  ristDelAction,
} from "@/api/risk/form";
import moment from "moment";
import creatRiskAction from "./creatRiskAction.vue";
import success from "@/views/risk/components/success.vue";
import axios from "axios";
import { DcoQuery, getUserList } from "@/api/common/form";
import userListSelect from "@/components/userListSelect/userListSelect.vue";
import { ACCESS_TOKEN } from "@/store/mutation-types";
const data = [];

export default {
  components: {
    creatRiskAction,
    success,
    userListSelect,
  },
  props: {
    // userList: {
    //   type: Array
    // },
    riskLevel: {
      type: Array,
    },
    riskType: {
      type: Array,
    },
    editId: {
      type: Number,
    },
    mode: {
      type: Number,
    },
  },
  data() {
    return {
      StateType: '',
      timerId: "",
      disabled: false,
      listLoading: false,
      data,
      listData: [],
      //编辑的截止时间
      RiskDeadline: "",
      headers: {
        authorization: "authorization-text",
      },
      // 下面这些都是通的
      form: this.$form.createForm(this),
      visible: false,
      userDCOList: [],
      //审阅抽屉显示
      reviewVisible: false,
      saveLoading: false,
      subLoading1: false,
      subLoading2: false,
      // 这个要根据服务修改title
      // titleMap: ['新增风险', '修改风险'],
      titleMap: "",
      //risk主页面编辑id
      riskEditId: null,
      current: 0,
      // 时间配置
      config: {
        rules: [
          {
            type: "object",
            required: true,
            message: this.$t("user.verification-code.required111566110577285"),
          },
        ],
      },
      // 分页参数
      pagination: {
        page: 1, //当前页
        pageSize: 10, //每页条数
        total: 0, //总条数
        showQuickJumper: true,
        hideOnSinglePage: true,
      },
      submitId: "0",
      env: process.env.VUE_APP_BASE_API,
      //存上传文件接口地址
      urlList: [],
      //点新建时的风险Id
      riskId: null,
      //选择的riskAction列表ID
      RiskListSelectId: null,
      fileLists: [],
      userList: [],
      keyword: "",
      inputValue: "",
      // 修改的风险的数据
      riskData: {},
      // Action列表是否全都已提交
      riskActionListsStatus: true,
      // 判断是否是读取
      riskRead: true,
      canclick: false,
    };
  },

  computed: {
    rowSelection() {
      return {
        onChange: (selectedRowKeys, selectedRows) => {
          this.RiskListSelectId = [selectedRowKeys].join("");
        },
        getCheckboxProps: (record) => ({
          props: {
            disabled: record.name === "Disabled User", // Column configuration not to be checked
            name: record.name,
          },
        }),
      };
    },
  },
  methods: {
    /**
* 获取当前时间
*/
    currentTime() {
      var date = new Date();
      var year = date.getFullYear(); //月份从0~11，所以加一
      let month = date.getMonth();
      console.log("month", month);
      var dateArr = [
        date.getMonth() + 1,
        date.getDate(),
        date.getHours(),
        date.getMinutes(),
        date.getSeconds(),
      ];
      //如果格式是MM则需要此步骤，如果是M格式则此循环注释掉
      for (var i = 0; i < dateArr.length; i++) {
        if (dateArr[i] >= 1 && dateArr[i] <= 9) {
          dateArr[i] = "0" + dateArr[i];
        }
      }
      var strDate =
        year +
        "-" +
        dateArr[0] +
        "-" +
        dateArr[1]
      //此处可以拿外部的变量接收，也可直接返回  strDate:2022-05-01 13:25:30
      //this.date = strDate;
      console.log("strDate", strDate);
      return strDate;
    },
    // 正则校验查询数据
    filterOption1(input, option) {
      return (
        option.componentOptions.children[0].text
          .toLowerCase()
          .indexOf(input.toLowerCase()) >= 0
      );
    },
    /**
     * 计算当前Action是否都是已完成
     */
    async checkActionListsFinish() {
      // 判断Action列表是否都是已提交
      // 只有都是已提交才会出那个「提交审核」
      this.riskActionListsStatus = true;
      for (var i = 0; i < this.listData.length; i++) {
        if (this.listData[i].DpiaActionStatus != 4) {
          this.riskActionListsStatus = false;
        }
      }
    },
    /**
     *
     * @param {*} type 0 新增 1 修改 2 读取
     * @param {*} data 列表传过来的值
     */
    async open(mode, data = {}, editId) {
      this.userList = [];
      this.mode = mode;
      if (mode == 0) {
        this.titleMap = this.$t(
          "user.verification-code.required111566110577146"
        );
        this.mode = mode;
        this.visible = true;
        const res = await riskCreate();
        this.riskData = res.data;
        this.riskId = res.data.Id;
        await this.getList(this.riskId);
        // console.log(this.currentTime())
        this.form.setFieldsValue({
          RiskStartTime: this.currentTime(),
        })
        // this.updateRiskDeadline()
      }
      // 如果是修改
      else {
        this.titleMap = "";
        // 如果是读取，则直接设置读取的标志位
        if (parseInt(mode) === 1) {
          this.riskRead = true;
          this.titleMap = this.$t(
            "user.verification-code.required1115661833434"
          );
          this.disabled =
            data.RiskOwnerUserId !== this.$store.state.user.info.YtAdminName &&
            data.RiskOwnerUserId !== this.$store.state.user.info.userid &&
            data.RiskCreateUserId !== this.$store.state.user.info.userid;
          // this.canclick = this.$store.state.user.info.userid === // ddddddddwwwwwwwww
        }
        this.riskData = data;

        this.riskId = data.Id;
        this.userList.push({
          value: data.RiskOwnerUserId,
          label: data.RiskOwnerUserName,
        });
        this.riskEditId = editId;
        this.RiskDeadline = data.RiskDeadline;
        this.visible = true;
        this.editId = editId;
        await this.getList(this.editId);
        await this.$nextTick();
        //修改的时候需要给form赋值
        this.form.setFieldsValue({
          RiskName: data.RiskName,
          RiskDetail: data.RiskDetail,
          RiskOwnerUserId: data.RiskOwnerUserId
            ? data.RiskOwnerUserId
            : undefined,
          RiskLevel: data.RiskLevel == 0 ? undefined : data.RiskLevel,
          RiskStartTime: data.RiskStartTime
            ? moment(data.RiskStartTime, "YYYY-MM-DD")
            : null,
          RiskType: data.RiskType == 0 ? undefined : data.RiskType,
          RiskDcoUserId:
            data.RiskDcoUserId == " " ? undefined : data.RiskDcoUserId,
          RiskDeadline: data.RiskDeadline
            ? moment(data.RiskDeadline, "YYYY-MM-DD")
            : null,
          RiskRemark: data.RiskRemark,
          RiskDisposeDetail: data.RiskDisposeDetail,
        });

        if (data.File) {
          data.File.forEach((item, index) => {
            let name = item.RiskUploadUrl.split("/");
            this.fileLists.push({
              uid: index,
              name: name[name.length - 1],
              status: "done",
              url: item.RiskUploadUrl,
              RiskUploadType: 1,
              fileId: item.Id,
            });
          });
        }
        this.mode = mode;
      }
    },

    async filte1rOption(value) {
      this.inputValue = value;
      const { data } = await getUserList({
        UserEmail: value,
        UserName: value,
      });
      this.userList = null;
      this.userList = [];
      if (data.length > 0) {
        this.userList = data;
      }
    },

    //截止时间
    updateRiskDeadline() {
      const riskStartTime = this.currentTime();
      const riskDeadline = this.form.getFieldValue("RiskDeadline");
      if (riskStartTime && riskDeadline && riskStartTime > riskDeadline) {
        this.form.setFieldsValue({
          RiskDeadline: riskStartTime,
        });
      }
    },

    disabledDateDeadline(current) {
      if (this.mode == 1) {
        console.log(this.form.getFieldValue("RiskStartTime").format("YYYY-MM-DD"));
        const riskStartTime = this.form.getFieldValue("RiskStartTime").format("YYYY-MM-DD");
        return current && current.format("YYYY-MM-DD") < riskStartTime;
      }else{
        console.log(this.form.getFieldValue("RiskStartTime"));
        const riskStartTime = this.form.getFieldValue("RiskStartTime");
        return current && current.format("YYYY-MM-DD") < riskStartTime;
      }
    },
    async getList() {
      this.listLoading = true;
      const { page, pageSize } = this.pagination;
      try {
        //审批人DCO
        // 获取用户列表下拉
        const { data: userList } = await DcoQuery({ ApprovalAlias: "DCO" });
        this.userDCOList = userList;
        // 调用查询列表
        const { data } = await RISKActionList({
          ...{ page, pageSize },
          ...this.queryForm,
          RiskId: this.riskId,
        });
        // 解构赋值
        const { Page, PageSize, Total, Lists } = data;
        // 给table赋值
        this.listData = Lists || [];

        // 给分页数据赋值
        this.pagination = {
          page: Page,
          pageSize: PageSize,
          total: Total,
        };
        // 检查aciton是否都是已完成
        await this.checkActionListsFinish();
      } catch (error) {
        // 报错信息
        this.$message.error(error);
      } finally {
        // 不管成功失败都会执行
        this.listLoading = false;
      }
    },
    // 上传提交
    //文件上传
    async handleChange(e) {
      // 上传提交
      this.uploadLoading = true;
      let formdata = new FormData();
      formdata.append("file", e.file);
      try {
        const { status, data } = await axios({
          url: `${this.env}/v1/oss/upload`,
          method: "post",
          data: formdata,
          headers: {
            token: storage.get(ACCESS_TOKEN),
            tokens: storage.get("bmwToken") || "",
          },
        });
        if (status == 200 && data.code == 1) {
          if (data.data != "") {
            await this.$nextTick();
            var files = data.data;
            var index = this.fileLists.length;
            if (files != "" && files != undefined) {
              var fileName = files.split("/");
              this.fileLists.push({
                uid: index + 1,
                name: fileName[fileName.length - 1],
                status: "done",
                url: data.Url + data.data,
                fileId: data.Id,
              });
              // 上传文件完成后新增
              // 新增
              this.mode == 0
                ? this.urlList.push({
                  RiskUploadType: 1,
                  RiskId: this.riskId,
                  RiskUploadUrl: data.data,
                })
                : this.urlList.push({
                  RiskUploadType: 1,
                  RiskId: this.riskEditId,
                  RiskUploadUrl: data.data,
                });
            }
          }
        } else {
          this.$message.error(
            this.$t("user.verification-code.required111566110577282")
          );
        }
      } catch (error) {
        this.$message.error(error);
      } finally {
        this.uploadLoading = false;
      }
    },
    //删除上传文件
    async delFile(file) {
      const index = this.fileLists.indexOf(file);
      this.fileLists.splice(index, 1);
      await delRiskFile({ Id: file.fileId });
      return true;
    },
    previousPage() {
      this.current--;
    },
    nextPage() {
      const {
        form: { validateFields },
      } = this;
      validateFields({ fore: true }, async (err, values) => {
        try {
          if (!err) {
            this.current++;
          }
        } catch (error) {
          this.$message.error(error);
        } finally {
          // this.loading = false;
        }
      });
    },
    // 提交 通用的
    submit(type) {
      this.StateType = type
      const {
        form: { validateFields },
      } = this;
      // 按钮loading
      // this.loading = true;
      // validateFields 是校验form表单数据
      // force: true 是默认所有字段都校验
      // values 表单的值
      validateFields({ force: true }, async (err, values) => {
        const RiskStartTime = moment(values["RiskStartTime"]).format(
          "YYYY-MM-DD"
        );
        values["RiskStartTime"] = RiskStartTime;
        const RiskDeadline = moment(values["RiskDeadline"]).format(
          "YYYY-MM-DD"
        );
        values["RiskDeadline"] = RiskDeadline;
        const urlList = this.urlList;
        values["File"] = urlList;
        if (type === "add" || type === "save") {
          this.subLoading1 = true
          // 提交 & 保存
          values["RiskState"] = 3;
        } else if (type === "review") {
          this.subLoading2 = true
          // 提交审核
          values["RiskState"] = 2;
        } else {
          this.saveLoading = true
          // 草稿
          values["RiskState"] = 1;
        }

        if (!err) {
          for (let arr = 0; arr < this.userList.length; arr++) {
            if (this.userList[arr].value == values.RiskOwnerUserId) {
              values.RiskOwnerUserId = this.userList[arr].label;
              values.RiskOwnerUserName = this.userList[arr].label;
            }
          }
          for (let arr = 0; arr < this.userDCOList.length; arr++) {
            if (this.userDCOList[arr].value == values.RiskDcoUserId) {
              values.RiskDcoUserName = this.userDCOList[arr].label;
            }
          }

          try {
            if (this.mode == 0) {
              values["Id"] = this.riskId;
              const { data } = await riskCreate(values);
            } else {
              values["Id"] = this.editId;
              values.RiskOwnerUserId = values.RiskOwnerUserName;
              const { data } = await riskCreate(values);
            }

            // 如果成功就调用父页面当前组件的succeed上绑定的事件
            this.$emit("succeed");
            this.$message.success(
              this.$t("user.verification-code.required111566110577308")
            );
            //如果成功就关闭
            this.current++;
          } catch (error) {
            this.$message.error(error);
          } finally {
            this.saveLoading = false;
            this.subLoading1 = false
            this.subLoading2 = false
          }
        } else {
          setTimeout(() => {
            this.saveLoading = false;
            this.subLoading1 = false
            this.subLoading2 = false
          }, 600);
        }
      });
    },
    async showModal(state, editId) {
      if (state == "0") {
        //新建时获取actin ID
        const { data } = await ristCreateAction({ RiskId: this.riskId });
        await this.$refs.creatRiskAction.openAction(editId, data, state, 1);
      } else {
        //编辑
        try {
          const { data } = await RISKEditActionList({ Id: editId });
          this.mode !== 2 ? (this.mode = 1) : "";
          //传值回显
          await this.$refs.creatRiskAction.openAction(
            editId,
            data,
            this.riskData.RiskOwnerUserId ===
              this.$store.state.user.info.userid ||
              this.riskData.RiskOwnerUserId ===
              this.$store.state.user.info.name ||
              (this.riskData.RiskState === 1 &&
                this.riskData.RiskCreateUserId ===
                this.$store.state.user.info.userid)
              ? ""
              : 2,
            0
          ); // 当前登陆人
        } catch (error) {
          // 报错信息
          this.$message.error(error);
        } finally {
          // 不管成功失败都会执行
          this.listLoading = false;
        }
      }
    },
    // 删除
    async del(record) {
      this.listLoading = true;
      try {
        await ristDelAction({ Id: record.Id });
        this.$message.success(
          this.$t("user.verification-code.required111566110577133")
        );
        await this.getList(record.RiskId);
      } catch (error) {
        // 报错信息
        this.$message.error(error);
      } finally {
        // 不管成功失败都会执行
        this.listLoading = false;
      }
    },
    // 关闭 通用的
    close() {
      const {
        form: { validateFields },
      } = this;
      validateFields({ fore: true }, async (err, values) => {
        try {
          if (
            (this.mode === "0" && this.current === 1) ||
            (this.mode === "0" && this.current === 0)
          ) {
            this.$emit("data-updated", this.riskId);
          }
        } catch (error) {
          this.$message.error(error);
        } finally {
          this.loading = false;
        }
      });
      this.riskId = null;
      this.fileLists = [];
      this.urlList = [];
      this.$emit("initEditId");
      this.mode = "0";
      this.current = 0;
      this.$emit("getList");
      this.disabled = false;
      // 修改侧边栏状态
      this.visible = false;
      this.reviewVisible = false;
      // 清空form的值
      this.form.resetFields();
    },
    filterOption(input, option) {
      return (
        option.componentOptions.children[0].text
          .toLowerCase()
          .indexOf(input.toLowerCase()) >= 0
      );
    },
  },
};
</script>
<style lang="less" scoped>
.drawerHeader {
  margin: 20px;
}

.ant-pagination {
  float: right;
  padding-bottom: 60px;
}
</style>